<?php
namespace app\html\controller;
// use app\index\
class History extends Base
{
    public function index()
    {
        $id=request()->param('id'); 
        $viewPage=$this->getIndexPage($id);

        $article=db("cms_history");
        $channel=db("channel");
        $fname=$channel->where("id",$id)->value("name");  
        $where['status']=1;
        $where['cid']=$id; 
        $mess=$article->where($where)->order("sort asc , id DESC")->select();
        for ($i=0; $i < count($mess); $i++) { 
            $year=explode("-",$mess[$i]['occurtime'])[0];
            $mess[$i]['year']=$year;
            // $mess[$i]['year']=explode("-",$mess[$i]['title'])[0];
            $data[$year]['year']=$year;
            $data[$year]['child'][]=$mess[$i];
            // $fragments[$mess[$i]['year']]=array_column($mess,null,"year");
        }

        $pid=$channel->where("id=".$id)->value("pid");        
        if($pid > 0){
            $gcid=$pid;
            $pcid=$id;
            $lchannel=$this->get_left_channel($gcid);
            $gnavName=$channel->where("id=".$gcid)->value("name");         
            $pnavName=$channel->where("id=".$pcid)->value("name");
        }else{
            $gcid=$id;         
            $gnavName=$channel->where("id=".$gcid)->value("name");
        } 
        // SEO META关键字配置
        $meta=$this->getSeoMeta($gnavName,$pnavName,$mess);
        
        $modelx=$channel->where("id",$id)->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);
        $banner=$this->get_banner($gcid);
        $this->assign("banner",$banner);
        $this->assign("id",$id);
        $this->assign("pcid",$this->pcid);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("mess",$data);
        $this->assign("lchannel",$lchannel);
        $this->assign("gcid",$gcid);
        $this->assign("pcid",$pcid);
        $this->assign("fname",$fname);            
        return view($viewPage);
       
    }    
    public function detail()
    {
        $id=request()->param('id');       
        $article=db("cms_history");
        $channel=db("channel");

        $mess=$article->find($id);
        $fname=$channel->where("id",$mess['cid'])->value("name");
        $viewPage=$this->getDetailPage($mess['cid']);
        $pid=$channel->where("id=".$mess['cid'])->value("pid");
        // print_r($pid);exit;
        if($pid > 0){
            $gcid=$pid;
            $pcid=$mess['cid'];
            $lchannel=$this->get_left_channel($pcid);   
            $gnavName=$channel->where("id=".$gcid)->value("name");         
            $pnavName=$channel->where("id=".$pcid)->value("name");
        }else{
            $gcid=$mess['cid'];         
            $gnavName=$channel->where("id=".$gcid)->value("name");
        } 
        // SEO META关键字配置
        $meta=$this->getSeoMeta($gnavName,$pnavName,$mess);
        $this->assign("meta",$meta);

        $modelx=$channel->where("id",$mess['cid'])->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);
        $banner=$this->get_banner($gcid);
        $this->assign("banner",$banner);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("lchannel",$lchannel);
        $this->assign("pcid",$pcid);
        $this->assign("gcid",$gcid);
        $this->assign("fname",$fname);
        $this->assign("mess",$mess);
        return view($viewPage);
    }
}
